package com.resolution.dietaryassessment.view.mydietary;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.resolution.dietaryassessment.BaseActivity;
import com.resolution.dietaryassessment.R;
import com.resolution.dietaryassessment.listener.MyListener;
import com.resolution.dietaryassessment.view.mydietary.fragment.resultitem.FoodPagodaFrag;
import com.resolution.dietaryassessment.view.mydietary.fragment.resultitem.IntakeAssessFrag;
import com.resolution.dietaryassessment.view.mydietary.fragment.resultitem.ProteinSourceFrag;
import com.resolution.dietaryassessment.view.mydietary.fragment.resultitem.SecondaryRatioFrag;
import com.resolution.dietaryassessment.view.mydietary.fragment.resultitem.SourceEvaluationFrag;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import q.rorbin.verticaltablayout.VerticalTabLayout;
import q.rorbin.verticaltablayout.adapter.TabAdapter;
import q.rorbin.verticaltablayout.widget.ITabView;
import q.rorbin.verticaltablayout.widget.QTabView;

public class FoodResultActivity extends BaseActivity {

    private List<String> titles = new ArrayList<>();

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_food_result);
        initView();
        initTabLayout();
    }

    private void initView() {
        Button leave = findViewById(R.id.leave_btn);
        Button re_btn = findViewById(R.id.re_main);
        re_btn.setOnClickListener(v -> finish());
        leave.setOnClickListener(new MyListener(this));
    }

    private void initTabLayout() {
        Collections.addAll(titles,"营养素摄入评价","能量来源评价","餐次比评价",
                "蛋白质来源评价", "膳食宝塔评价");

        VerticalTabLayout tabLayout = findViewById(R.id.v_tablayout);
        List<Fragment> fragments = getFragments();
        tabLayout.setupWithFragment(getSupportFragmentManager(), R.id.item_holder, fragments,
                new TabAdapter() {
                    @Override
                    public int getCount() {
                        return titles.size();
                    }

                    @Override
                    public ITabView.TabBadge getBadge(int position) {
                        return null;
                    }

                    @Override
                    public ITabView.TabIcon getIcon(int position) {
                        return null;
                    }

                    @Override
                    public ITabView.TabTitle getTitle(int position) {
                        return new QTabView.TabTitle.Builder()
                                .setContent(titles.get(position))
                                .setTextColor(getResources().getColor(R.color.colorWhite), getResources().getColor(R.color.colorMidBlack))
                                .build();
                    }
                    @Override
                    public int getBackground(int position) {
                        return R.color.colorWeakOrange;
                    }
                });
        tabLayout.setTabSelected(0);
    }

    private List<Fragment> getFragments() {
        List<Fragment> fragments = new ArrayList<>();
        Collections.addAll(fragments,IntakeAssessFrag.newInstance(),
                SourceEvaluationFrag.newInstance(),
                SecondaryRatioFrag.newInstance(),
                ProteinSourceFrag.newInstance(),
                FoodPagodaFrag.newInstance());
        return fragments;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        finish();
    }
}
